//
//  SLInfoAddCell.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/22.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit

class SLInfoAddCell: UITableViewCell, UITextFieldDelegate {
    var tfBlock:SLBlock?
    enum CellType {
        case defaul
        case select
        case phone
    }
    func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
        print("结束输入")
        if let block = self.tfBlock {
            block(self.textField.text ?? "")
        }
        return true
    }

    lazy var tfView:UIView = {
        let v = create_view(bgColor: rgba(hex: "#F3F6F9"), supView: self.contentView) { make in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.bottom.equalTo(0)
            make.height.equalTo(44)
        }
        v.layer.masksToBounds = true
        v.layer.cornerRadius = 10
        return v
    }()
    lazy var textField:UITextField = {
        let pt = create_textField(text: "", textColor: .black,textFont: SLFontConfig.regular(size: 16), supView: self.tfView) { make in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        pt.delegate = self
        return pt
    }()
    
    lazy var titleL:UILabel = {
        let pt = create_label(text: "", textColor: rgba(hex: "#999999"),textFont: SLFontConfig.medium15,alignment:.left, supView: self.contentView) { make in
            make.bottom.equalTo(tfView.snp.top).offset(-8)
            make.left.equalTo(15)
            make.right.equalTo(-15)
       
        }
        pt.numberOfLines = 0
        return pt
    }()
    lazy var line:UIView = {
        let pt = create_view(bgColor: rgba(hex: "#070707",a: 0.05), supView: self.contentView) { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.bottom.equalTo(0)
            make.height.equalTo(1)
        }
        pt.isHidden = true
        return pt
    }()
    func setType(type: CellType){
        if type == .defaul{
            self.textField.isUserInteractionEnabled = true
            self.arrow.isHidden = true
            self.phone.isHidden = true
        }else if type == .select{
            self.textField.isUserInteractionEnabled = false
            self.arrow.isHidden = false
            self.phone.isHidden = true
        }else if type == .phone{
            self.textField.isUserInteractionEnabled = false
            self.arrow.isHidden = true
            self.phone.isHidden = false
        }
        self.selectionStyle = .none
        self.contentView.backgroundColor = .white
        self.backgroundColor = .white
    }
    func setPlaceholderText(place: String){

        let attributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: rgba(hex: "#8F8F8F") // 修改 placeholder 颜⾊
        ]
        let attributedPlaceholder = NSAttributedString(string: place, attributes: attributes)
        self.textField.attributedPlaceholder = attributedPlaceholder
        
    }
    lazy var arrow:UIImageView = {
        let pt = create_imageView(image: IMAGE("arrow.alt.right"), supView: self.tfView) { make in
            make.right.equalTo(-15)
            make.centerY.equalTo(self.textField.snp.centerY)
            make.width.height.equalTo(16)
        }
        return pt
    }()
    lazy var phone:UIImageView = {
        let pt = create_imageView(image: IMAGE("phone"), supView: self.tfView) { make in
            make.right.equalTo(-16)
            make.centerY.equalTo(self.textField.snp.centerY)
            make.width.equalTo(18)
            make.height.equalTo(18);
        }
        return pt
    }()

    
}

